import TbColumn from "@/components/table/tbColumn";
import { isNull } from "@/utils/service";

/** 表格值保留两位小数且空值将以 '-' 字符替代 */
function percentageWithFixedDigits2(row, column, cellValue, index) {
  if(typeof(cellValue) === 'number'){
    return cellValue.toFixed(2);
  }else if (typeof(cellValue) === 'string'){
    return cellValue ? cellValue : '-'
  }else {
    return '-'
  }
}
/** 表格空值将以 '-' 字符替代 */
function valueToCharacter(row, column, cellValue, index){
  return !isNull(cellValue) ? cellValue : '-'
}
function formatDateToDay(dateStr) {
  const date = new Date(dateStr.dataDate);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');

  return `${year}-${month}-${day}`;
}

export const COLUMNS = [
  new TbColumn("店铺名称", "storeName", {
    width: 200, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("数据日期", "dataDate", {
    width: 120, sortable: true, align: "center", formatter: formatDateToDay }),
  new TbColumn("支付金额", "amountPaid", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("退款金额", "refundAmount", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("访客数量","visitorsNum", {
    width: 120, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("支付转化率","payTransformRate", {
    width: 120, sortable: true, align: "center" }),
  new TbColumn("直通车花费","ztcSpend", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("引力魔方花费","ylmfSpend", {
    width: 130, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("万象台花费","wxtSpend", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("直播间金额","liveRoomAmount", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("直通车成交额","ztcTransactionAmount", {
    width: 130, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("引力魔方成交额","ylmfTransactionAmount", {
    width: 150, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("万象台成交额","wxtTransactionAmount", {
    width: 130, sortable: true, align: "center", formatter: percentageWithFixedDigits2}),
  new TbColumn("补单数","fillOrderNum", {
    width: 100, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("刷单金额","brushOrdersAmount", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("创建时间", "createTime", {
    width: 180, sortable: true, align: "center" }),
  new TbColumn("修改时间", "updateTime", {
    width: 180, sortable: true, align: "center" }),
];